<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>NeuZephyr: nz::nodes::calc::MaxPoolingNode Class Reference</title>
<link rel="icon" href="NZ_logo2.png" type="image/x-icon" />
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="NZ_logo2.png"/></td>
  <td id="projectalign">
   <div id="projectname">NeuZephyr
   </div>
   <div id="projectbrief">Simple DL Framework</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.12.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>nz</b></li><li class="navelem"><a class="el" href="namespacenz_1_1nodes.html">nodes</a></li><li class="navelem"><a class="el" href="namespacenz_1_1nodes_1_1calc.html">calc</a></li><li class="navelem"><a class="el" href="classnz_1_1nodes_1_1calc_1_1_max_pooling_node.html">MaxPoolingNode</a></li>  </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classnz_1_1nodes_1_1calc_1_1_max_pooling_node-members.html">List of all members</a>  </div>
  <div class="headertitle"><div class="title">nz::nodes::calc::MaxPoolingNode Class Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Implements max pooling operation for spatial downsampling with feature preservation.  
 <a href="#details">More...</a></p>
<div class="dynheader">
Inheritance diagram for nz::nodes::calc::MaxPoolingNode:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_max_pooling_node__inherit__graph.png" border="0" usemap="#anz_1_1nodes_1_1calc_1_1_max_pooling_node_inherit__map" alt="Inheritance graph"/></div>
<map name="anz_1_1nodes_1_1calc_1_1_max_pooling_node_inherit__map" id="anz_1_1nodes_1_1calc_1_1_max_pooling_node_inherit__map">
<area shape="rect" title="Implements max pooling operation for spatial downsampling with feature preservation." alt="" coords="5,80,223,107"/>
<area shape="rect" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph." alt="" coords="55,5,173,32"/>
<area shape="poly" title=" " alt="" coords="117,48,117,80,111,80,111,48"/>
</map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<div class="dynheader">
Collaboration diagram for nz::nodes::calc::MaxPoolingNode:</div>
<div class="dyncontent">
<div class="center"><img src="classnz_1_1nodes_1_1calc_1_1_max_pooling_node__coll__graph.png" border="0" usemap="#anz_1_1nodes_1_1calc_1_1_max_pooling_node_coll__map" alt="Collaboration graph"/></div>
<map name="anz_1_1nodes_1_1calc_1_1_max_pooling_node_coll__map" id="anz_1_1nodes_1_1calc_1_1_max_pooling_node_coll__map">
<area shape="rect" title="Implements max pooling operation for spatial downsampling with feature preservation." alt="" coords="5,80,223,107"/>
<area shape="rect" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph." alt="" coords="55,5,173,32"/>
<area shape="poly" title=" " alt="" coords="117,48,117,80,111,80,111,48"/>
</map>
<center><span class="legend">[<a href="graph_legend.html">legend</a>]</span></center></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a56018af1d41b8058deabe63c38e03c0d" id="r_a56018af1d41b8058deabe63c38e03c0d"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a56018af1d41b8058deabe63c38e03c0d">MaxPoolingNode</a> (<a class="el" href="classnz_1_1nodes_1_1_node.html">Node</a> *input, Tensor::size_type poolSize, Tensor::size_type stride, Tensor::size_type padding)</td></tr>
<tr class="memdesc:a56018af1d41b8058deabe63c38e03c0d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructs a <a class="el" href="classnz_1_1nodes_1_1calc_1_1_max_pooling_node.html" title="Implements max pooling operation for spatial downsampling with feature preservation.">MaxPoolingNode</a> object.  <br /></td></tr>
<tr class="separator:a56018af1d41b8058deabe63c38e03c0d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2dd8c57551f76d957ef97121c6df2adc" id="r_a2dd8c57551f76d957ef97121c6df2adc"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a2dd8c57551f76d957ef97121c6df2adc">forward</a> () override</td></tr>
<tr class="memdesc:a2dd8c57551f76d957ef97121c6df2adc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Performs the forward pass of the max - pooling operation.  <br /></td></tr>
<tr class="separator:a2dd8c57551f76d957ef97121c6df2adc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae0a0a0b7303101c4417564babf0fcd5f" id="r_ae0a0a0b7303101c4417564babf0fcd5f"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ae0a0a0b7303101c4417564babf0fcd5f">backward</a> () override</td></tr>
<tr class="memdesc:ae0a0a0b7303101c4417564babf0fcd5f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Performs the backward pass of the max - pooling operation.  <br /></td></tr>
<tr class="separator:ae0a0a0b7303101c4417564babf0fcd5f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="inherit_header pub_methods_classnz_1_1nodes_1_1_node"><td colspan="2" onclick="javascript:dynsection.toggleInherit('pub_methods_classnz_1_1nodes_1_1_node')"><img src="closed.png" alt="-"/>&#160;Public Member Functions inherited from <a class="el" href="classnz_1_1nodes_1_1_node.html">nz::nodes::Node</a></td></tr>
<tr class="memitem:a687ee9c34eb61f8f28caa201ca42696e inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_a687ee9c34eb61f8f28caa201ca42696e"><td class="memItemLeft" align="right" valign="top">virtual void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#a687ee9c34eb61f8f28caa201ca42696e">print</a> (std::ostream &amp;os) const</td></tr>
<tr class="memdesc:a687ee9c34eb61f8f28caa201ca42696e inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Prints the type, data, and gradient of the node.  <br /></td></tr>
<tr class="separator:a687ee9c34eb61f8f28caa201ca42696e inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9b85913e12422bb4ac2fff483427bb47 inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_a9b85913e12422bb4ac2fff483427bb47"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#a9b85913e12422bb4ac2fff483427bb47">dataInject</a> (Tensor::value_type *data, bool grad=false) const</td></tr>
<tr class="memdesc:a9b85913e12422bb4ac2fff483427bb47 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Injects data into a relevant tensor object, optionally setting its gradient requirement.  <br /></td></tr>
<tr class="separator:a9b85913e12422bb4ac2fff483427bb47 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_a609f1730085dd1d31e0ddcbbae48a065"><td class="memTemplParams" colspan="2">template&lt;typename Iterator &gt; </td></tr>
<tr class="memitem:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#a609f1730085dd1d31e0ddcbbae48a065">dataInject</a> (Iterator begin, Iterator end, const bool grad=false) const</td></tr>
<tr class="memdesc:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Injects data from an iterator range into the output tensor of the InputNode, optionally setting its gradient requirement.  <br /></td></tr>
<tr class="separator:a609f1730085dd1d31e0ddcbbae48a065 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af8b4bab3271df92ca1f0914f7a97b1e8 inherit pub_methods_classnz_1_1nodes_1_1_node" id="r_af8b4bab3271df92ca1f0914f7a97b1e8"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classnz_1_1nodes_1_1_node.html#af8b4bab3271df92ca1f0914f7a97b1e8">dataInject</a> (const std::initializer_list&lt; Tensor::value_type &gt; &amp;data, bool grad=false) const</td></tr>
<tr class="memdesc:af8b4bab3271df92ca1f0914f7a97b1e8 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="mdescLeft">&#160;</td><td class="mdescRight">Injects data from a std::initializer_list into the output tensor of the <a class="el" href="classnz_1_1nodes_1_1_node.html" title="Base class for nodes in a neural network or computational graph.">Node</a>, optionally setting its gradient requirement.  <br /></td></tr>
<tr class="separator:af8b4bab3271df92ca1f0914f7a97b1e8 inherit pub_methods_classnz_1_1nodes_1_1_node"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Implements max pooling operation for spatial downsampling with feature preservation. </p>
<p>This node performs spatial max selection over sliding windows of (poolSize x poolSize) dimensions, maintaining the most prominent features while reducing spatial resolution. Essential for preserving sharp feature responses in CNNs.</p>
<p>Core functionality and characteristics:</p><ul>
<li><b>Feature Selection</b>: Captures maximum activation values within local receptive fields.</li>
<li><b>Position Tracking</b>: Records max value locations via position tensor for gradient computation.</li>
<li><b>Sparse Gradient Flow</b>: Propagates gradients only to winning positions during backward pass.</li>
<li><b>Dimensionality Control</b>: Reduces H/W dimensions while preserving channel structure.</li>
<li><b>Border Handling</b>: Supports configurable padding for output size management.</li>
<li><b>CUDA Optimization</b>: Accelerated implementations for both forward and backward operations.</li>
<li><b>Dynamic Shape Adaption</b>: Automatically calculates output dimensions using pooling parameters.</li>
</ul>
<p>Key implementation aspects:</p><ul>
<li><b>Forward Pass</b>: Computes max values and stores positions using parallelized argmax operations.</li>
<li><b>Backward Pass</b>: Scatters gradients exclusively to original max positions with 1:1 mapping.</li>
<li><b>Memory Tradeoff</b>: Stores position indices (poolSize^2 elements per window) for gradient accuracy.</li>
<li><b>Numerical Stability</b>: Handles multiple equal maxima by selecting first occurrence.</li>
</ul>
<p>Typical use cases:</p><ul>
<li>Dominant feature extraction in early CNN layers</li>
<li>Downsampling while preserving edge/texture information</li>
<li>Constructing translation-invariant representations</li>
<li>Reducing computational load in deep networks</li>
</ul>
<p>Critical considerations:</p><ul>
<li><b>Information Discard</b>: Non-maximal values are irreversibly discarded during forward pass</li>
<li><b>Dimension Constraints</b>: Output dimensions must satisfy: Hout = (H + 2*padding - poolSize)/stride + 1</li>
<li><b>Position Storage</b>: Requires O(N*C*Hout*Wout) memory for position tracking</li>
</ul>
<dl class="section warning"><dt>Warning</dt><dd><ul>
<li>Invalid dimension combinations will throw runtime errors</li>
<li>Overly aggressive pooling (poolSize &gt;&gt; stride) may cause feature loss</li>
<li>Position tensor initialization must match forward pass execution order</li>
</ul>
</dd></dl>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Output shape: (N, C, Hout, Wout)</li>
<li>For variable pooling windows, extend with additional size parameters</li>
<li>Compared to average pooling, better preserves feature sharpness</li>
</ul>
</dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classnz_1_1nodes_1_1calc_1_1_average_pooling_node.html" title="Implements average pooling operation for spatial downsampling in neural networks.">AveragePoolingNode</a> For smoothing-based spatial aggregation </dd>
<dd>
<a class="el" href="classnz_1_1nodes_1_1calc_1_1_global_avg_pool_node.html" title="Performs global average pooling operation across spatial dimensions of input tensor.">GlobalAvgPoolNode</a> For complete spatial dimension collapse</dd></dl>
<h3><a class="anchor" id="autotoc_md111"></a>
Usage Example:</h3>
<div class="fragment"><div class="line"><span class="comment">// Process 32 samples of 128x128 RGB images</span></div>
<div class="line">InputNode input({32, 3, 128, 128}, <span class="keyword">true</span>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Create 3x3 max pooling with stride 2 and padding 1</span></div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_max_pooling_node.html">MaxPoolingNode</a> mpool(&amp;input, 3, 2, 1);</div>
<div class="line">mpool.forward();</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Resulting shape: (32, 3, 64, 64)</span></div>
<div class="line">std::cout &lt;&lt; <span class="stringliteral">&quot;Pooled shape: &quot;</span> &lt;&lt; mpool.output-&gt;shape() &lt;&lt; std::endl;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Backpropagate gradients through max positions</span></div>
<div class="line">mpool.backward();</div>
<div class="ttc" id="aclassnz_1_1nodes_1_1calc_1_1_max_pooling_node_html"><div class="ttname"><a href="classnz_1_1nodes_1_1calc_1_1_max_pooling_node.html">nz::nodes::calc::MaxPoolingNode</a></div><div class="ttdoc">Implements max pooling operation for spatial downsampling with feature preservation.</div><div class="ttdef"><b>Definition</b> <a href="_nodes_8cuh_source.html#l04440">Nodes.cuh:4440</a></div></div>
</div><!-- fragment --><dl class="section author"><dt>Author</dt><dd>Mgepahmge (<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2023/10/21 </dd></dl>

<p class="definition">Definition at line <a class="el" href="_nodes_8cuh_source.html#l04440">4440</a> of file <a class="el" href="_nodes_8cuh_source.html">Nodes.cuh</a>.</p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a56018af1d41b8058deabe63c38e03c0d" name="a56018af1d41b8058deabe63c38e03c0d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a56018af1d41b8058deabe63c38e03c0d">&#9670;&#160;</a></span>MaxPoolingNode()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">nz::nodes::calc::MaxPoolingNode::MaxPoolingNode </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classnz_1_1nodes_1_1_node.html">Node</a> *</td>          <td class="paramname"><span class="paramname"><em>input</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">Tensor::size_type</td>          <td class="paramname"><span class="paramname"><em>poolSize</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">Tensor::size_type</td>          <td class="paramname"><span class="paramname"><em>stride</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">Tensor::size_type</td>          <td class="paramname"><span class="paramname"><em>padding</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Constructs a <a class="el" href="classnz_1_1nodes_1_1calc_1_1_max_pooling_node.html" title="Implements max pooling operation for spatial downsampling with feature preservation.">MaxPoolingNode</a> object. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">input</td><td>A pointer to the input node. Memory of this pointer is assumed to be managed externally and used in a read - only way within the constructor (host - to - host). </td></tr>
    <tr><td class="paramname">poolSize</td><td>The size of the pooling window, of type <code>Tensor::size_type</code>. It is passed by value. </td></tr>
    <tr><td class="paramname">stride</td><td>The stride of the pooling operation, of type <code>Tensor::size_type</code>. It is passed by value. </td></tr>
    <tr><td class="paramname">padding</td><td>The padding applied to the input tensor, of type <code>Tensor::size_type</code>. It is passed by value.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<p>This constructor initializes a <a class="el" href="classnz_1_1nodes_1_1calc_1_1_max_pooling_node.html" title="Implements max pooling operation for spatial downsampling with feature preservation.">MaxPoolingNode</a> object. It first stores the provided <code>poolSize</code>, <code>stride</code>, and <code>padding</code> values. Then, it adds the input node pointer to the <code>inputs</code> vector. Next, it creates a new shared pointer to a Tensor object for the <code>output</code> member. The shape of the output tensor is calculated based on the input tensor's shape, <code>poolSize</code>, <code>stride</code>, and <code>padding</code> using the <code>OUTPUT_DIM</code> macro. The <code>requiresGrad</code> flag of the output tensor is set to the same value as that of the input tensor's output. Additionally, it creates a new shared pointer to a Tensor object for the <code>position</code> member. The shape of the <code>position</code> tensor is the same as that of the output tensor, and its <code>requiresGrad</code> flag is set to <code>false</code>.</p>
<p>Memory management strategy: The constructor does not allocate memory for the input node. It only stores a pointer to it. The <code>output</code> and <code>position</code> tensors are created using <code>std::make_shared</code>, which manages their memory automatically. Exception handling mechanism: There is no explicit exception handling in this constructor. If the <code>std::make_shared</code> calls fail to allocate memory for the <code>output</code> or <code>position</code> tensors, they may throw a <code>std::bad_alloc</code> exception.</p>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">std::bad_alloc</td><td>If memory allocation for the <code>output</code> or <code>position</code> tensors fails.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Ensure that the input node pointer is valid and points to a properly initialized node.</li>
<li>The performance of this constructor is mainly determined by the memory allocation for the <code>output</code> and <code>position</code> tensors, which has a time complexity of O(1) for the pointer management and O(m) for the tensor data allocation, where m is the number of elements in the tensors.</li>
</ul>
</dd></dl>
<div class="fragment"><div class="line">```cpp</div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1_node.html">Node</a>* inputNode = <span class="keyword">new</span> <a class="code hl_class" href="classnz_1_1nodes_1_1_node.html">Node</a>(...); <span class="comment">// Assume Node is properly initialized</span></div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_max_pooling_node.html">MaxPoolingNode</a> maxPoolingNode(inputNode, 2, 2, 0);</div>
<div class="line">```</div>
<div class="ttc" id="aclassnz_1_1nodes_1_1_node_html"><div class="ttname"><a href="classnz_1_1nodes_1_1_node.html">nz::nodes::Node</a></div><div class="ttdoc">Base class for nodes in a neural network or computational graph.</div><div class="ttdef"><b>Definition</b> <a href="_nodes_8cuh_source.html#l00114">Nodes.cuh:114</a></div></div>
</div><!-- fragment --><dl class="section author"><dt>Author</dt><dd>Mgepahmge(<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/07/15 </dd></dl>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00716">716</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="ae0a0a0b7303101c4417564babf0fcd5f" name="ae0a0a0b7303101c4417564babf0fcd5f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae0a0a0b7303101c4417564babf0fcd5f">&#9670;&#160;</a></span>backward()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void nz::nodes::calc::MaxPoolingNode::backward </td>
          <td>(</td>
          <td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">override</span><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Performs the backward pass of the max - pooling operation. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">None</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<p>This function conducts the backward pass of the max - pooling operation. It first checks if the output tensor of the input node requires gradient computation. If it does, it calls the <code>iMaxPoolingBackward</code> function, passing the gradient pointer of the input node's output, the data pointer of the position tensor, the gradient pointer of the output tensor, the pooling parameters (<code>poolSize</code>, <code>stride</code>, <code>padding</code>), and the shape information of the input and output tensors. The <code>iMaxPoolingBackward</code> function is responsible for computing the gradients and propagating them back to the input tensor.</p>
<p>Memory management strategy: This function does not allocate or deallocate any memory directly. It operates on the existing gradient tensors of the input and output, as well as the data tensor of the position. Exception handling mechanism: There is no explicit exception handling in this function. If the <code>iMaxPoolingBackward</code> function encounters an error, it may throw an exception depending on its implementation.</p>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">[Exception</td><td>type from iMaxPoolingBackward] If the <code>iMaxPoolingBackward</code> function encounters an error during execution.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Ensure that the input, output, and position tensors' gradient and data are properly initialized before calling this function.</li>
<li>The performance of this function depends on the implementation of the <code>iMaxPoolingBackward</code> function. The time complexity typically depends on the size of the input tensor and the pooling parameters, and may be O(b * c * h * w) in the worst - case scenario, where b is the batch size, c is the number of channels, h is the height, and w is the width of the input tensor.</li>
</ul>
</dd></dl>
<div class="fragment"><div class="line">```cpp</div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_max_pooling_node.html">MaxPoolingNode</a> maxPoolingNode(...); <span class="comment">// Assume MaxPoolingNode is properly initialized</span></div>
<div class="line">maxPoolingNode.backward();</div>
<div class="line">```</div>
</div><!-- fragment --><dl class="section author"><dt>Author</dt><dd>Mgepahmge(<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/07/15 </dd></dl>

<p>Implements <a class="el" href="classnz_1_1nodes_1_1_node.html#a0a9ecbaa3d790ba38e8218aca7837fd0">nz::nodes::Node</a>.</p>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00737">737</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>

</div>
</div>
<a id="a2dd8c57551f76d957ef97121c6df2adc" name="a2dd8c57551f76d957ef97121c6df2adc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2dd8c57551f76d957ef97121c6df2adc">&#9670;&#160;</a></span>forward()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void nz::nodes::calc::MaxPoolingNode::forward </td>
          <td>(</td>
          <td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">override</span><span class="mlabel">virtual</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Performs the forward pass of the max - pooling operation. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">None</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<p>This function executes the forward pass of the max - pooling operation. It calls the <code>iMaxPooling</code> function, passing the data pointers of the output tensor, the position tensor, and the input tensor's output. It also provides the pooling parameters (<code>poolSize</code>, <code>stride</code>, <code>padding</code>) and the shape information of the input and output tensors. The <code>iMaxPooling</code> function is responsible for computing the max - pooling result and storing it in the output tensor, as well as recording the positions of the maximum values in the position tensor.</p>
<p>Memory management strategy: This function does not allocate or deallocate any memory directly. It operates on the existing data tensors of the input, output, and position. Exception handling mechanism: There is no explicit exception handling in this function. If the <code>iMaxPooling</code> function encounters an error, it may throw an exception depending on its implementation.</p>
<dl class="exception"><dt>Exceptions</dt><dd>
  <table class="exception">
    <tr><td class="paramname">[Exception</td><td>type from iMaxPooling] If the <code>iMaxPooling</code> function encounters an error during execution.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>Ensure that the input, output, and position tensors are properly initialized before calling this function.</li>
<li>The performance of this function depends on the implementation of the <code>iMaxPooling</code> function. The time complexity typically depends on the size of the input tensor and the pooling parameters, and may be O(b * c * h * w) in the worst - case scenario, where b is the batch size, c is the number of channels, h is the height, and w is the width of the input tensor.</li>
</ul>
</dd></dl>
<div class="fragment"><div class="line">```cpp</div>
<div class="line"><a class="code hl_class" href="classnz_1_1nodes_1_1calc_1_1_max_pooling_node.html">MaxPoolingNode</a> maxPoolingNode(...); <span class="comment">// Assume MaxPoolingNode is properly initialized</span></div>
<div class="line">maxPoolingNode.forward();</div>
<div class="line">```</div>
</div><!-- fragment --><dl class="section author"><dt>Author</dt><dd>Mgepahmge(<a href="https://github.com/Mgepahmge">https://github.com/Mgepahmge</a>)</dd></dl>
<dl class="section date"><dt>Date</dt><dd>2024/07/15 </dd></dl>

<p>Implements <a class="el" href="classnz_1_1nodes_1_1_node.html#a8a828c2e91a4aa2a9ab7b94554e4685b">nz::nodes::Node</a>.</p>

<p class="definition">Definition at line <a class="el" href="_nodes_8cu_source.html#l00731">731</a> of file <a class="el" href="_nodes_8cu_source.html">Nodes.cu</a>.</p>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>D:/Users/Mgepahmge/Documents/C Program/NeuZephyr/include/NeuZephyr/<a class="el" href="_nodes_8cuh_source.html">Nodes.cuh</a></li>
<li>D:/Users/Mgepahmge/Documents/C Program/NeuZephyr/src/<a class="el" href="_nodes_8cu_source.html">Nodes.cu</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.12.0
</small></address>
</div><!-- doc-content -->
</body>
</html>
